<?php
class MiddleLink {
	public function __construct()
	{
		
	}
	
	function middleLink()
	{
		//CommonFunc::loadFile("model/Common.php");
		//$modCommon = new Common();
		$module_arr = $_SERVER['QUERY_STRING']; 
		$module_arr = explode("/", $module_arr);
		$module = $module_arr[0];
		$param1 = $module_arr[1];
		$param2 = $module_arr[2];
		$param3 = $module_arr[3];
		$param4 = $module_arr[4];
		
		$subcat = $param2;
		$cat_desc = $this->getCategoryBySubCat($subcat);
		
		echo $cat_desc;
	}

        public function getCategoryBySubCat($subcat)
	{
		$sql1 = "SELECT cat_desc AS CAT
				FROM tbl_category
				WHERE cat_id IN
					(SELECT parent_id
						FROM tbl_category
						WHERE cat_id = " . $subcat . "
					)
				";

		$qry1 = DB::fetchRow($sql1);

		$sql2 = "SELECT parent_id, cat_desc AS SUBCAT
				 FROM tbl_category
				 WHERE cat_id = " . $subcat;

		$qry2 = DB::fetchRow($sql2);
		$parent_id = $qry2['parent_id'];

		if($qry1['CAT'] != "")
		{
				
			$rtString = "<div class='breadcrumb cblock  maindisplay'>";
			$rtString .= "<a href='" . SITEURL . "'>Home</a> &rsaquo; <a href='" . SITEURL . "index.php/?viewproducts/cat/" . $parent_id . "'>" . $qry1['CAT'] . "</a> &rsaquo; " . $qry2['SUBCAT'];
			$rtString .= "</div>";
			return $rtString;
			
		} else {
			return "";
			$rtString = "<div class='breadcrumb cblock  maindisplay'>";
			$rtString .= "<a href='" . SITEURL . "'>Home</a> &rsaquo; " . $qry2['SUBCAT'];
			$rtString .= "</div>";
			return $rtString;
		}
	}
}
?>